<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand" />
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<title>课堂任务-精准微课堂</title>
	<%@ include file="/common/commonLib.jsp"%>
	<link rel="stylesheet" type="text/css" href="<c:url value='/css/classroomIndex.css'/>" />
	<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
	<link rel="stylesheet" type="text/css" href="<c:url value='/wangEditor/dist/css/wangEditor.css'/>" />
	<link rel="stylesheet" type="text/css" href="<c:url value='/css/checkboxcss/inserthtml.com.radios.css'/>" />
	<script src="<c:url value='/js/classroomIndex.js'/>" type="text/javascript" charset="utf-8"></script>
</head>

<body>
	
	<div class="container-fluid main">
		<%@include file="/common/header.jsp"%>
		<%@include file="common/classroomHeader.jsp"%>
		
		<div class="row classroom-index-con">
			<div class="col-md-12 col-lg-12">
				<div class="classroom-index-con-content">
					<div class="row">
						<div class="col-md-1"></div>
						<div class="col-md-10">
							<%@include file="common/classroomNav.jsp"%>
						</div>
						<div class="col-md-1"></div>
					</div>
					<div class="row">
						<!-- 课堂任务 -->
						<div class="classroom-task">
							<div class="row">
								<!--任务列表 -->
								<div class="col-md-1"></div>
								<div class="col-md-10">
									<!-- 新建任务 -->
									<div class="col-md-12" style="text-align:right;">
										<shiro:hasRole name="teacher">
											<input type="button" class="btn btn-primary" id="new-lesson-task-btn" value="创建当堂提问任务">
										</shiro:hasRole>
									</div>
									<!-- 任务列表 -->
									<div class="col-md-12">
										<table class="table table-hover" id="task-list-table">
											<thead>
												<tr>
													<th>
														<select onchange="search()" class="form-control" id="searchTaskType">
															<option value="ALL" selected = "selected">全部</option>
															<option value="ASKINLESSON">课堂提问</option>
															<option  value="TESTINLESSON">当堂测试</option>
															<option value="HOMEWORK">课后作业</option>
															<option value="LABTEST">实验任务</option>
														</select>
													</th>
													<th>任务名</th>
													<th>截止时间</th>
													<th>发布者</th>
													<th>
														<select onchange="search()" class="form-control" id="searchIsVisible">
															<option value="ALL" selected = "selected">全部</option>
															<option value="YES">已发布</option>
															<option value="NO">预发布</option>
														</select>
													</th>
												</tr>
											</thead>
											<tbody id="taskList">
											</tbody>
										</table>
									</div>
								</div>
								<div class="col-md-1"></div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<%@include file="/common/footer.jsp"%>
	
	<div id="new-lesson-task" style="display:none;">
		<div class="row">
			<div class="col-md-1"></div>
			<div class="col-md-10">
				<!-- 任务名称 -->
				<div class="col-md-12">
					<div class="col-md-6 form-group">
						<label>任务名称</label>
						<input id="new-lesson-task-name" type="text" class="form-control" placeholder="任务名称">
					</div>
				</div>
				<!-- 提问人数 -->
				<div class="col-md-12">
					<div class="col-md-6 form-group">
						<label>提问人数</label>
						<input id="new-lesson-task-askNumber" type="number" class="form-control" placeholder="提问人数" min="1">
					</div>
				</div>
				<!-- 任务描述 -->
				<div class="col-md-12">
					<div class="col-md-12">
						<span style="color:#00b43c;font-weight:bolder;">添加任务描述</span>
						<input type="checkbox" id="checkbox" /><label for="checkbox"></label>
					</div>
					<div class="col-md-12">
						<div id="task-description-box">
							<label>任务描述</label>
							<div id="editor-task">
							
							</div>
						</div>
					</div>
				</div>
				<!-- 创建并发布任务 -->
				<div class="col-md-12" style="text-align:center;margin-bottom:4rem;">
					<input type="button" class="btn btn-primary" id="creat-lesson-task-btn" value="创建">
				</div>
			</div>
			<div class="col-md-1"></div>
		</div>
	</div>
	<script src="<c:url value='/wangEditor/dist/js/wangEditor.js'/>" type="text/javascript" charset="utf-8"></script>
</body>
<script>
var data=${data};
$(document).ready(function(){
	if (data.status != "success"){
		alert(data.message);
		return;
	}
	$("#classroom-href-task").css("color","#00b43c");
	initNewTask();
	
	$("#task-description-box").hide();
	initLesson(data.data.lessonId);//初始化课堂信息
	initTable(data.data);
	changeLessonUrl(data.data.lessonId);//初始化导航链接
});

$(function() {
	
	$("#new-lesson-task-btn").click(function() {
		var index = layer.open({
			type: 1,
			title: '新建当堂提问任务',
			fixed: false, //不固定
			maxmin: true,
			closeBtn: 1,
			scrollbar: false,
			area: ['90rem', '45rem'],
			content: $("#new-lesson-task"),
			end: function () {
                location.reload();
            }
		});
		layer.full(index);
	});
	
	$("#checkbox").click(function() {
		if($("#checkbox").is(":checked")) {
			$("#task-description-box").show();
		} else {
			$("#task-description-box").hide();
		}
	});
	$("#creat-lesson-task-btn").click(function() {
		addLessonTask();
	});
	
});

var LessonTaskCreate = function(json){
	$.post(CONTEXT_PATH+"task/ajaxCreateLessonTask", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			//window.location.reload();
			layer.msg("创建成功！");
			window.location.replace(CONTEXT_PATH+"lessonTaskInLessonDetail/detail?id="+data.data.taskAssignmentId);
		}else{
			alert(data.message);
		}
	});
}

var addLessonTask= function (){
	var lessonId=data.data.lessonId;
	var type="ASKINLESSON";
	var title =$("input[id='new-lesson-task-name']").val();
	if(title==null||title==""||title==" "){
		title=getTypeStr(type)+"-"+$(".classroom-course-name").html()+"-"+$(".classroom-time").html();
	}
	var description=$("#editor-task").html();
	var numsOfAnswerers = $("input[id='new-lesson-task-askNumber']").val();
	var isVisible = "YES";
	var json={
			lessonId:lessonId,
			type:type,
			title:title,
			numsOfAnswerers:numsOfAnswerers,
			description:description,
			isVisible:isVisible,
			isAnswerVisible:"NO"
	};
	LessonTaskCreate(json);
}

var initNewTask= function() {
	var editorNewTask = new wangEditor('editor-task');
	editorNewTask.config.menus = [
	    'fullscreen',' | ','bold','underline','italic','strikethrough','eraser',
		'forecolor','bgcolor','quote','fontfamily','fontsize','head','unorderlist',
		'orderlist','alignleft','aligncenter','alignright','link','unlink','table',
		'emotion','img','video','insertcode','undo','redo'
    ];
	editorNewTask.config.uploadImgUrl = CONTEXT_PATH + 'resource/editUpload';
	editorNewTask.config.uploadImgFileName='editor-task';
	editorNewTask.config.zindex = 20000;
	editorNewTask.create();
	$('#editor-task').attr('style','height:auto;');
}

var initTask = function (json){//
	$.get(CONTEXT_PATH+"lessonTaskView/ajaxTlview", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			initTable(data.data);
		}else{
			alert(data.message);
		}
	});	
}

var getTypeStr=function(type){
	var taskType="";
	if(type=="ASKINLESSON"){
		taskType="课堂提问";
	}else if(type=="TESTINLESSON"){
		taskType="当堂测试";
	}else if(type=="HOMEWORK"){
		taskType="课后作业";
	}else if(type=="LABTEST"){
		taskType="实验任务";
	}
	return taskType;
}
 
var initTable = function(data){
	var taskList=$("#taskList");
	taskList.empty();
	var list=data.list;
	if(list.length <= 0){
		var s = "<tr><td colspan=\"5\">暂无任务</td></tr>";
		taskList.append(s);
	}
	for(var i=0;i<list.length;i++){
		var item=list[i];
		var isVisible="预发布";
		if(item.isVisible=="YES"){
			isVisible="已发布";
		}else{
			isVisible="预发布";
		}
		
		var ctlist = "";
		ctlist += ("<tr onclick=\"window.location.href=");
		
		if(item.type=="ASKINLESSON"){
			ctlist += ("'<c:url value='/lessonTaskInLessonDetail/detail?id="+item.assignId+"'/>'\">");
		}else{
			ctlist += ("'<c:url value='/lessonTaskMainDetail/detail?id="+item.assignId+"'/>'\">");
		}
		ctlist += ("<td  title=\""+getTypeStr(item.type)+"\">"+getTypeStr(item.type)+"</td>");
		ctlist += ("<td title=\""+item.title+"\">"+item.title+"</td>");
		if(item.type=="ASKINLESSON"){
			ctlist += ("<td>---</td>");
		}else{
			ctlist += ("<td title=\""+item.deadline+"\">"+item.deadline+"</td>");
		}
		ctlist += ("<td title=\""+item.createName+"\">"+item.createName+"</td>");
		ctlist += ("<td title=\""+isVisible+"\">"+isVisible+"</td>");
		ctlist += ("</tr>");
		
		taskList.append(ctlist);
	}
}

var search = function(){
	
	var taskType=$("#searchTaskType  option:selected").val();
	var isVisible =$("#searchIsVisible  option:selected").val();
	var json={
			lessonId:data.data.lessonId,
			type:taskType,
			isVisible:isVisible
	};
	if(isVisible=="ALL"){
		delete json.isVisible;
	};
	if(taskType=="ALL"){
		delete json.type;
	}
	initTask(json);
}

</script>
</html>